package com.ja.openchat.ui.me;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.Nullable;

import com.blankj.utilcode.util.BarUtils;
import com.ja.openchat.BR;
import com.ja.openchat.R;
import com.ja.openchat.databinding.FragmentSetBinding;
import com.ja.openchat.viewmodels.SetViewModel;

import me.goldze.mvvmhabit.base.BaseFragment;
import me.goldze.mvvmhabit.utils.StatusBarUtil;

//设置
public class SetFragment extends BaseFragment<FragmentSetBinding, SetViewModel> implements View.OnClickListener {

    @Override
    public int initContentView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return R.layout.fragment_set;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }


    @Override
    public void initView() {
        BarUtils.setStatusBarColor(getActivity(), getResources().getColor(R.color.color_f7f7f7));

        binding.tvLogout.setOnClickListener(this);
    }

    @Override
    public void onResume() {
        super.onResume();
        viewModel.requestInfoData();
    }

    private void logoutTip() {
        AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity());
        dialog.setTitle(R.string.dialog_title_tip).setMessage(getString(R.string.log_out_account_hint));
        dialog.setPositiveButton(R.string.dialog_ok,
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        viewModel.logout();
                    }
                });
        dialog.setNegativeButton(R.string.dialog_cancel, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        dialog.show();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_logout:
                logoutTip();
                break;
        }
    }
}